/**
  ******************************************************************************
  * @author     Chris
  * @since      2024/6/18 10:40
  *
  * @file       pd_timer_encoder.h
  * @brief      Header file of Timer Encoder Interface hardware driver.
  *
  * @note       This file contains the Timer Encoder Interface object declaration.
  *
  * @warning    None.
  ******************************************************************************
  * Change Logs:
  *   Date          Author       Notes
  *   2024/6/18     Chris        the first version
  *
  ******************************************************************************
  */


#ifndef JLC_SKY_TIMER_ENCODER_H
#define JLC_SKY_TIMER_ENCODER_H

#include "pd_timer.h"
#include "pd_timer_ic.h"
#include "pd_timer_ch.h"

struct TimerEncoderVtbl;

/** @defgroup Object properties
  * @{
  */
typedef struct {
    Timer *timer;
    TimerCh *timerChannel;

    uint32_t EncoderMode;
    uint32_t IC1Polarity;
    uint32_t IC1ActiveInput;
    uint32_t IC1Prescaler;
    uint32_t IC1Filter;
    uint32_t IC2Polarity;
    uint32_t IC2ActiveInput;
    uint32_t IC2Prescaler;
    uint32_t IC2Filter;

    // TimerEncoder virtual table
    struct TimerEncoderVtbl* vptr;
} TimerEncoder;
/**
 * @}
 */

/** @defgroup Object virtual table definition
  * @{
  */
struct TimerEncoderVtbl {
    void (*init)(const TimerEncoder *this);

    int16_t (*get_counter)(const TimerEncoder *this);
};
/**
 * @}
 */

/** @defgroup Object constructor and member function declaration
  * @{
  */
void TimerEncoder_constructor(TimerEncoder *this, Timer *timer, TimerCh *timerChannel);
/**
 * @}
 */

/** @defgroup Object virtual table function implementation
  * @{
  */
static inline void TimerEncoder_init(const TimerEncoder *this) {
  this->vptr->init(this);
}

static inline int16_t TimerEncoder_getCounter(const TimerEncoder *this) {
  return this->vptr->get_counter(this);
}
/**
 * @}
 */


#endif //JLC_SKY_TIMER_ENCODER_H
